package week3;


public class Ex23 {
    public static void main(String[] args) {
        int m = 28123;
        int[] overArr = new int[m];
        int c = 0;
        int sumOfFactors, factor;
        for (int i = 12; i + 12 <= m; i++) {
            sumOfFactors = 1;
            int q = (int)Math.sqrt(i);
            for (factor = 2; factor < q; ++factor){
                if (i % factor == 0){
                    sumOfFactors += factor;
                    sumOfFactors += i / factor;
                }
            }
            if (i % q == 0) {
                sumOfFactors += q;
                if (q * q != i)
                    sumOfFactors += i / q;
            }
            if (sumOfFactors > i)
                overArr[++c] = i;
        }
        boolean[] flag = new boolean[m+1];
        for (int i = 1; i <= c; ++i){
            for (int j = i; j <= c; ++j) {
                if (overArr[i] + overArr[j] <= m)
                    flag[overArr[i]+overArr[j]] = true;
            }
        }
        int ans = 0;
        for (int i = 1; i <= m; i++){
            if (!flag[i])
                ans += i;
        }
        System.out.println(ans);
    }
}
